package com.rohoo.user.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.rohoo.user.bo.Register;
import com.rohoo.user.dao.RegisterDAO;
import com.rohoo.user.dto.RegisterDTO;
import com.rohoo.user.service.RegisterService;

public class RegisterServiceImpl implements RegisterService{
	
	private Log log = LogFactory.getLog(getClass());
	
	RegisterDAO registerDAO;
	
	public int selUserId() throws Exception {
		int result;
		try {
			result = registerDAO.selUserId();
		} catch (Exception ex) {
			if (log.isErrorEnabled())
				log.error("selUserId Error!", ex);
			throw new Exception("selUserId Error!", ex);
		}
		return result;
	}
	
	public boolean add(Register register) throws Exception{
		boolean result;
		try {
			result=registerDAO.add(register);
		} catch (Exception e) {
			result=false;
			throw new Exception("RegisterServiceImpl add Error!", e);
		}
		return result;
	}
	
	public int getUserId(String useridcard) throws Exception{
		int result;
		try {
			result = registerDAO.getUserId(useridcard);
		} catch (Exception ex) {
			if(log.isErrorEnabled())
				log.error("getUserId Error!", ex);
			throw new Exception("getUserId Error!", ex);
		}
		return result;
	}
	
	public Register getUser(int user_id) throws Exception {
		try{
			Register user = registerDAO.getUser(user_id);
			return user;
		}catch (Exception e) {
			throw new Exception("RegisterServiceImpl getUser Error!", e);
		}
	}

	public void updateUser(RegisterDTO dto) throws Exception {
		try {
			registerDAO.updateUser(dto);
		} catch (Exception e) {
			throw new Exception("RegisterServiceImpl updateUser Error!", e);
		}
	}

	public RegisterDAO getRegisterDAO() {
		return registerDAO;
	}

	public void setRegisterDAO(RegisterDAO registerDAO) {
		this.registerDAO = registerDAO;
	}
}
